package com.iting.test.controller;

import com.iting.bean.Student;
import com.iting.test.properties.MyProperties;
import com.iting.test.service.MyService;
import com.iting.test.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author iting Nie
 * @version 1.1
 * @create 2022/1/7
 */
@RestController
public class HelloController {

	@Autowired
	private MyService myService;
	@Autowired
	private RedisService redisService;

	public HelloController() {
		System.out.println("HelloController");
	}

	@RequestMapping("/hello")
	public String hello(){
		System.out.println("sayHello");
		redisService.set("a","a");
		redisService.get("a");
		return "hello world";
	}

	@RequestMapping("/demo")
	public MyProperties demo(){
		return myService.demo();
	}

	@RequestMapping("/name")
	public String name(String name){
		return name;
	}

	@RequestMapping("/date")
	public String date(Date date){
		if (date == null){
			return "null";
		}
		return date.toString();
	}
	@RequestMapping("/student")
	public Student student(Student student){
		System.out.println(student.getName());
		System.out.println(student.getAge());
		System.out.println("student方法执行了");
		return student;
	}

	@RequestMapping("/exceptiondemo")
	public void exceptionDemo(){
		throw new RuntimeException();
	}

}
